package org.openwebtop.sunshine.action.common;

import org.openwebtop.sunshine.bo.DashboardBO;
import org.openwebtop.sunshine.model.Component;
import org.openwebtop.sunshine.subversion.SubversionClient;
import org.openwebtop.sunshine.subversion.SubversionClientFactory;
import org.openwebtop.sunshine.subversion.model.FileInfo;

import com.opensymphony.xwork.ActionSupport;

public class ViewFileAction {
	private DashboardBO dashboardBO;
	private SubversionClientFactory subversionClientFactory;

	// Params
	private int id;
	private long revision;
	private String path;

	// Getter
	private Component component;
	private FileInfo fileInfo;

	public String execute() throws Exception {
		component = dashboardBO.getComponent(id);

		if (component != null) {
			final SubversionClient client = subversionClientFactory.getSubversionClient(component);
			fileInfo = client.getFileContents(path, revision, "EUC-KR");
		}

		return ActionSupport.SUCCESS;
	}

	public void setDashboardBO(DashboardBO dashboardBO) {
		this.dashboardBO = dashboardBO;
	}

	public void setSubversionClientFactory(SubversionClientFactory subversionClientFactory) {
		this.subversionClientFactory = subversionClientFactory;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setRevision(long revision) {
		this.revision = revision;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public FileInfo getFileInfo() {
		return fileInfo;
	}

}
